﻿namespace WLFramework.IoC
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    internal class IocRegisterService<T> :
        BaseIoCRegisterService, IIocRegisterService<T>
    {
        private readonly int _hashCode;
        private readonly string _typeName;

        public IocRegisterService(Func<IIocContainer, T> create) :
            base(ioc => create(ioc))
        {
            var type = typeof(T).FullName;
            this._hashCode = type.GetHashCode();
            this._typeName = type;
        }

        public override string Type
        {
            get { return this._typeName; }
        }

        public override bool Equals(object obj)
        {
            return obj is IocRegisterService<T> &&
                ((IocRegisterService<T>)obj).Type.Equals(this.Type);
        }

        public override int GetHashCode()
        {
            return this._hashCode;
        }

        public T GetTypedInstance(IIocContainer ioc, bool createNew)
        {
            return (T)base.GetInstance(ioc, createNew);
        }
    }
}
